var app = getApp();
var core = require('../../utils/core.js')
var util = require('../../utils/util.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let userInfo = app.getCache("userinfo")
    let url = ''
    let tokenid = app.getCache("tokenid")
    var pages = getCurrentPages();
    wx.showLoading({
      title: '加载中',
    })
    core.getToken(function (res) {
      if (res == "success") {
        app.setCache('tokennum', '0')
        let prevPage = app.getCache('prevPage')
        if (prevPage) {
          if (prevPage == 'pages/goods/index/index' || prevPage == 'pages/index/index' || prevPage == 'pages/active/index' || prevPage == 'pages/member/cart/index' || prevPage == 'pages/member/index/index') {
            setTimeout(() => {
              wx.switchTab({
                url: '/' + prevPage,
              })
              wx.hideLoading({
                complete: (res) => {},
              })
            }, 1500)
          } else {
            setTimeout(() => {
              wx.redirectTo({
                url: '/' + prevPage,
              })
              wx.hideLoading({
                complete: (res) => {},
              })
            }, 1500)
          }
          app.removeCache('prevPage')
        } else {
          setTimeout(() => {
            wx.switchTab({
              url: '/pages/index/index',
            })
            wx.hideLoading({
              complete: (res) => {},
            })
          }, 1000)

        }

      } else if (res == "fail") {}

    })
    // }
  },
})